export const GET_HOMELIST = 'GET_HOMELIST' //获取拼单列表
export const PUSH_HOMELIST = 'PUSH_HOMELIST' //添加拼单列表
export const OPEN_MASK = 'OPEN_MASK'  //活动弹框
export const UPDATE_MASK = 'UPDATE_MASK'  //活动弹框  更改活动弹窗是否展示
export const GET_BANNER = 'GET_BANNER'  // 首页banner
export const TODAY_HOT = 'TODAY_HOT'  // 每日最火
export const HOME_COLLAGE = 'HOME_COLLAGE'  // 首页拼购推荐
export const HOME_SHARE = 'HOME_SHARE'   // 首页共享推荐
export const HOME_CITYCALL = 'HOME_CITYCALL' //首页全球集市


export const GET_HOMEHONEYBANNER = 'GET_HOMEHONEYBANNER'  // 首页蜜享banner
export const GET_HOMEBUYINGBANNER = 'GET_HOMEBUYINGBANNER'  // 首页蜜享banner

export const GET_HOMEZONEBANNER = 'GET_HOMEZONEBANNER'  // 首页专区banner
export const GET_HOMENEWZONEBANNER = 'GET_HOMENEWZONEBANNER'  // 首页专区banner
export const GET_HOMEFLOATBANNER = 'GET_HOMEFLOATBANNER'  // 首页专区banner
export const GET_HOMETTHREEZONEBANNER = 'GET_HOMETTHREEZONEBANNER'  // 首页新闻资讯

export const GET_SIGNOUTBANNER = 'GET_SIGNOUTBANNER'  // 商家联盟专区banner


export const GET_CITYBANNER = 'GET_CITYBANNER'  // 百城好货banner
export const GET_CITYZONEBANNER = 'GET_CITYZONEBANNER'  // 百城好货banner


export const SET_HOMEMENU = 'SET_HOMEMENU'  //首页菜单按钮
export const GET_SORTLIST = 'GET_SORTLIST'  //分类商品列表
export const PUSH_SORTLIST = 'PUSH_SORTLIST'  //分类商品列表
export const GET_SORTBANNER = 'GET_SORTBANNER'  //分类商品banner
export const GET_EATBANNER = 'GET_EATBANNER'  //分类商品banner
export const GET_EATZONE = 'GET_EATZONE'  //分类商品banner


export default {
  state: {
    obj: JSON.parse(window.localStorage.getItem('homeList')) || {},
    sortList: JSON.parse(window.localStorage.getItem('sortList')) || {},
    openMask: [],
    banner: [],
    todayHot: [],
    homeCollage: [],
    homeShare: [],
    homeCityCall: [],
    HomeHoneyBanner: {arr: []},
    HomeBuyingBanner: {arr: []},
    homeZoneBanner: {arr: []},
    homeNewZoneBanner: {arr: []},
    homeThreeZoneBanner: JSON.parse(window.localStorage.getItem('homeThreeZoneBanner')) || {arr: []},
    homeFloatBanner: {arr: []},
    cityBanner: JSON.parse(window.localStorage.getItem('cityBanner')) || {arr: []},
    cityZoneBanner: JSON.parse(window.localStorage.getItem('cityZoneBanner')) || {arr: []},
    signoutBanner: [],
    homeMenu: JSON.parse(window.localStorage.getItem('homeMenu')) || {arr: []},
    eatBanner: JSON.parse(window.localStorage.getItem('eatBanner')) || {arr: []},
    sortBanner: JSON.parse(window.localStorage.getItem('sortBanner')) || {arr: []},
    eatZone: JSON.parse(window.localStorage.getItem('eatZone')) || {arr: []},
  },
  mutations: {
    [GET_SORTLIST](state, data) {
      state.sortList = data;
      window.localStorage.setItem('sortList', JSON.stringify(data))
    },
    [GET_SORTBANNER](state, data) {
      state.sortBanner.arr = data;
      window.localStorage.setItem('sortBanner', JSON.stringify(state.sortBanner))
    },
    [GET_EATBANNER](state, data) {
      state.eatBanner.arr = data;
      window.localStorage.setItem('eatBanner', JSON.stringify(state.eatBanner))
    },
    [GET_EATZONE](state, data) {
      state.eatZone.arr = data;
      window.localStorage.setItem('eatZone', JSON.stringify(state.eatZone))
    },
    [PUSH_SORTLIST](state, data) {
      for (let i = 0; i < data.length; i++) {
        let obj = data[i];
        state.sortList.push(obj);
      }
      window.localStorage.setItem('sortList', JSON.stringify(state.sortList))
    },
    [GET_HOMELIST](state, data) {
      state.obj = data;
      window.localStorage.setItem('homeList', JSON.stringify(data))
    },
    [PUSH_HOMELIST](state, data) {
      for (let i = 0; i < data.length; i++) {
        let obj = data[i];
        state.obj.push(obj);
      }
      window.localStorage.setItem('homeList', JSON.stringify(state.obj))
    },
    [OPEN_MASK](state, data) {
      state.openMask = data
    },
    [UPDATE_MASK](state, data) {
      state.openMask[data.index].flag = data.value
      console.log(state.openMask)
    },
    [GET_BANNER](state, data) {
      state.banner = data
    },
    [GET_HOMEHONEYBANNER](state, data) {
      state.HomeHoneyBanner.arr = data
    },
    [GET_HOMEBUYINGBANNER](state, data) {
      state.HomeBuyingBanner.arr = data
    },
    [TODAY_HOT](state, data) {
      state.todayHot = data
    },
    [HOME_COLLAGE](state, data) {
      state.homeCollage = data
    },
    [HOME_SHARE](state, data) {
      state.homeShare = data
    },
    [HOME_CITYCALL](state, data) {
      state.homeCityCall = data
    },
    [GET_HOMEZONEBANNER](state, data) {
      state.homeZoneBanner.arr = data
    },
    [GET_HOMENEWZONEBANNER](state, data) {
      state.homeNewZoneBanner.arr = data
    },
    [GET_HOMEFLOATBANNER](state, data) {
      state.homeFloatBanner.arr = data
    },
    [GET_SIGNOUTBANNER](state, data) {
      state.signoutBanner = data
    },
    [GET_HOMETTHREEZONEBANNER](state, data) {
      state.homeThreeZoneBanner.arr = data
      window.localStorage.setItem('homeThreeZoneBanner', JSON.stringify(state.homeThreeZoneBanner))
    },
    [GET_CITYBANNER](state, data) {
      state.cityBanner.arr = data
      window.localStorage.setItem('cityBanner', JSON.stringify(state.cityBanner))
    },
    [GET_CITYZONEBANNER](state, data) {
      state.cityZoneBanner.arr = data
      window.localStorage.setItem('cityZoneBanner', JSON.stringify(state.cityZoneBanner))
    },
    [SET_HOMEMENU](state, data) {
      state.homeMenu = {arr: data}
      window.localStorage.setItem('homeMenu', JSON.stringify(state.homeMenu))
    },
  },
  actions: {
    [GET_SORTLIST]({commit}, data) {
      commit(GET_SORTLIST, data)
    },
    [GET_SORTBANNER]({commit}, data) {
      commit(GET_SORTBANNER, data)
    },
    [GET_EATBANNER]({commit}, data) {
      commit(GET_EATBANNER, data)
    },
    [GET_EATZONE]({commit}, data) {
      commit(GET_EATZONE, data)
    },
    [PUSH_SORTLIST]({commit}, data) {
      commit(PUSH_SORTLIST, data)
    },
    [GET_HOMELIST]({commit}, data) {
      commit(GET_HOMELIST, data)
    },
    [PUSH_HOMELIST]({commit}, data) {
      commit(PUSH_HOMELIST, data)
    },
    [OPEN_MASK]({commit}, data) {
      commit(OPEN_MASK, data)
    },
    [UPDATE_MASK]({commit}, data) {
      commit(UPDATE_MASK, data)
    },
    [GET_BANNER]({commit}, data) {
      commit(GET_BANNER, data)
    },
    [TODAY_HOT]({commit}, data) {
      commit(TODAY_HOT, data)
    },
    [HOME_COLLAGE]({commit}, data) {
      commit(HOME_COLLAGE, data)
    },
    [HOME_SHARE]({commit}, data) {
      commit(HOME_SHARE, data)
    },
    [HOME_CITYCALL]({commit}, data) {
      commit(HOME_CITYCALL, data)
    },
    [GET_HOMEHONEYBANNER]({commit}, data) {
      commit(GET_HOMEHONEYBANNER, data)
    },
    [GET_HOMEBUYINGBANNER]({commit}, data) {
      commit(GET_HOMEBUYINGBANNER, data)
    },
    [GET_HOMEZONEBANNER]({commit}, data) {
      commit(GET_HOMEZONEBANNER, data)
    },
    [GET_HOMENEWZONEBANNER]({commit}, data) {
      commit(GET_HOMENEWZONEBANNER, data)
    },
    [GET_HOMEFLOATBANNER]({commit}, data) {
      commit(GET_HOMEFLOATBANNER, data)
    },
    [GET_SIGNOUTBANNER]({commit}, data) {
      commit(GET_SIGNOUTBANNER, data)
    },
    [GET_HOMETTHREEZONEBANNER]({commit}, data) {
      commit(GET_HOMETTHREEZONEBANNER, data)
    },
    [GET_CITYBANNER]({commit}, data) {
      commit(GET_CITYBANNER, data)
    },
    [GET_CITYZONEBANNER]({commit}, data) {
      commit(GET_CITYZONEBANNER, data)
    },
    [SET_HOMEMENU]({commit}, data) {
      commit(SET_HOMEMENU, data)
    },
  }
}